package com.itheima.service.impl;

import com.itheima.dao.GoodsDao;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.TableData;
import com.itheima.pojo.Goods;
import com.itheima.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;

    @Override
    public TableData findByPage(QueryPageBean queryPageBean) {
        Integer index = (queryPageBean.getCurrentPage()-1)*queryPageBean.getPageSize();
        queryPageBean.setIndex(index);
        List<Goods> goodsList = goodsDao.findByPage(queryPageBean);
        Long total = goodsDao.findTotal();
        TableData tableData = new TableData(goodsList, total);
        return tableData;
    }

    @Override
    public void add(Goods goods) {
        goodsDao.add(goods);
    }

    @Override
    public void edit(Goods goods) {
        goodsDao.edit(goods);
    }

    @Override
    public void delById(Integer id) {
        goodsDao.delById(id);
    }
}
